#ifndef __DESCRIPTOR__
#define __DESCRIPTOR__

#include "../lib/define.h"

#define DESC_G_4K 0x00800000
#define DESC_D_32 0x00400000
#define DESC_L 0x00200000
#define DESC_AVL 0x00100000
#define DESC_P 0x00008000
#define DESC_DPL_0 0x00000000
#define DESC_DPL_1 0x00002000
#define DESC_DPL_2 0x00004000
#define DESC_DPL_3 0x00006000
#define DESC_TYPE_SYSTEM 0x00000000
#define DESC_TYPE_CODE 0x00001800
#define DESC_TYPE_DATA 0x00001000
#define DESC_CODE_CONFIRMING 0x00000400
#define DESC_CODE_READABLE 0x00000200
#define DESC_CODE_ACCESSED 0x00000100
#define DESC_DATA_EXTEND_DIR 0x00000400
#define DESC_DATA_WRITABLE 0x00000200
#define DESC_DATA_ACCESSED 0x00000100

#define INTR_TYPE_INT16 0x06
#define INTR_TYPE_TRAP16 0x07
#define INTR_TYPE_INT32 0x0E
#define INTR_TYPE_TRAP32 0x0F
#define INTR_TYPE_TASK32 0x05
#define INTR_TYPE_CALL 0x0C

#define INTR_DPL_0 0x00
#define INTR_DPL_1 0x20
#define INTR_DPL_2 0x40
#define INTR_DPL_3 0x60

#define INTR_P 0x80

#define SEG_RPL0 0x0000
#define SEG_RPL1 0x0001
#define SEG_RPL2 0x0002
#define SEG_RPL3 0x0003

#define SEG_TI_GDT 0x0000
#define SEG_TI_LDT 0x0004

#define PG_P 0x00000001
#define PG_RW_W	0x00000002
#define PG_US_U	0x00000004
#define PG_ACC 0x00000020

typedef struct GDT_DESC {
  WORD LimitLow;
  WORD BaseLow;
  BYTE BaseMid;
  BYTE Attribute1;
  BYTE LimitHighAndAttribute2;
  BYTE BaseHigh;
} * PGDT_DESC, *LPGDT_DESC;

typedef struct IDT_DESC {
  WORD OffsetLow;
  WORD Selector;
  BYTE Count;
  BYTE Attribute;
  WORD OffsetHigh;
} * PIDT_DESC, *LPIDT_DESC;

typedef void *IntrHandler;
typedef void *SyscallProc;

#define SYSCALL_INTR 0x80
#define SYSCALL_CNT 0x100
#define IDT_DESC_CNT 0x81
#define INTR_ENTRY_CNT 0x80

#endif
